learner_id=`expr $2 - 1`;
proposer_id=`expr $2 - 1`;

all_folder="all/"
cpu_folder="cpu/"
lat_folder="lat/"

delimeter="/"
txt_postfix=".txt"
pidstat="pidstat"$txt_postfix;
top="top"$txt_postfix;

ip1=$1;
ip2=`expr $1 + $2 `;
config_file=$3;
general_path=$4;
interval=$5;
num_packets_per_interval=$6
folder_id=$7;
 


for((i=ip2 -1; i>=ip1; i--))
do
    echo $i 

             pidstat_path=$general_path$folder_id$delimeter$cpu_folder$proposer_id$pidstat;
                 top_path=$general_path$folder_id$delimeter$cpu_folder$proposer_id$top;
    performance_file_path=$general_path$folder_id$delimeter$all_folder$proposer_id$txt_postfix;
        latency_file_path=$general_path$folder_id$delimeter$lat_folder$proposer_id$txt_postfix;
         
    echo $performance_file_path;
    
    ssh -f -n "node"${i} "pidstat 1 |grep learner- >> $pidstat_path";
    ssh -f -n "node"${i} "top -b -d 1 | grep learner- >> $top_path";
    
    if((i==ip1))
    	then
    		ssh -f -n "node"${i} "/home/parisa/RING-PAXOS-JOURNAL/svn/RP-original/learner-proposer/learner-proposer $learner_id $proposer_id $interval $num_packets_per_interval $config_file $performance_file_path $latency_file_path 1";
    else
			ssh -f -n "node"${i} "/home/parisa/RING-PAXOS-JOURNAL/svn/RP-original/learner-proposer/learner-proposer $learner_id $proposer_id $interval $num_packets_per_interval $config_file $performance_file_path $latency_file_path 0";
	fi
    ((proposer_id-=1));
    ((learner_id-=1));
done

